<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

//会员管理

class Member extends Admin_Controller{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('admin/user_model');

    }
    //会员列表
     public function index(){
         $data['users'] = $this->user_model->list_user();
         $data['nums'] = $this->user_model->count_user();
         $this->load->view('member-list.html',$data);
     }

     public function changestatus(){
        $user_id = $this->input->get("user_id");
        $status =  $this->input->get("status");
        $user = $this->user_model->get_user($user_id);

        if(!empty($user)){
            $data['status'] = $status;
            if($this->user_model->update($data,$user_id)){

                $message = $status==1 ? '启用':'停用';
                $mess = array();
                $mess['status'] = $status;
                $mess['stat'] = 1;
                $mess['message'] = $message.'成功';
                $mess['url'] = base_url().'admin/member/index';
                echo json_encode($mess);
                exit();
            }else{
                $message = $status==1 ? '启用':'停用';
                $mess = array();
                $mess['status'] = $status;
                $mess['stat'] = 1;
                $mess['message'] = $message.'失败';
                $mess['url'] = base_url().'admin/member/index';
                echo json_encode($mess);
                exit();
            }

        }else{
            exit('非法操作');
        }
     }

     //删除
    public function del(){
        $user_id = $this->input->get("user_id");
        $user = $this->user_model->get_user($user_id);
        if(!empty($user)){
            if($this->user_model->delete($user_id)){
                $mess = array();
                $mess['stat'] = 1;
                $mess['message'] ='删除用户成功';
                $mess['url'] = base_url().'admin/member/index';
                echo json_encode($mess);
                exit();
            }else{
                $mess = array();
                $mess['stat'] = 1;
                $mess['message'] = '删除用户失败';
                $mess['url'] = base_url().'admin/member/index';
                echo json_encode($mess);
                exit();
            }

        }else{
            exit('非法操作');
        }
    }





}